package com.api.oa.mapper;

import com.api.oa.model.entity.YQNews;
import com.api.oa.model.vo.OaNoticeVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQNewsMapper {

    @Insert("insert into  yq_news  (" +
            "newUrl," +
            "newIcon," +
            "newTitle," +
            "newDesc," +
            "newContent," +
            "newType," +
            "createdAt" +
            ") " +
            "values " +
            "(" +
            "#{entity.newUrl}," +
            "#{entity.newIcon}," +
            "#{entity.newTitle}," +
            "#{entity.newDesc}," +
            "#{entity.newContent}," +
            "#{entity.newType}," +
            "#{entity.createdAt}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "newId", keyColumn = "id")
    Integer insert(@Param("entity") YQNews entity);


    @Update("update  yq_news  set " +
            "newId = #{entity.newId}," +
            "newUrl = #{entity.newUrl}," +
            "newIcon = #{entity.newIcon}," +
            "newTitle = #{entity.newTitle}," +
            "newDesc = #{entity.newDesc}," +
            "newContent = #{entity.newContent}," +
            "newType = #{entity.newType}," +
            "createdAt = #{entity.createdAt}" +
            " where newId = #{entity.newId}")
    Integer update(@Param("entity") YQNews entity);


    @Delete("delete from yq_news where newId=#{id}")
    void delete(@Param("id") Long id);


    @Select("<script> select * from  yq_news where 1=1" +
            " <if test='keyWord!=null and keyWord!=\"\"'> and concat(ifnull(newTitle,''),ifnull(newDesc,'')) like concat('%',#{keyWord},'%') </if>" +
            " <if test='newType!=null and newType!=\"\"'> and newType=#{newType} </if>" +
            "  </script>")
    List<YQNews> list(@Param("keyWord") String keyWord, @Param("newType") String type);


    @Select("select * from  yq_news  where newId = #{id} limit 1")
    YQNews findOne(@Param("id") Long id);

}

